class Promise{
    constructor(excutor){
        this.status = 'pending';
        //用来存储成功或失败的回调函数
        //成功的事件池
        this.fulfilledEvent = [];
        //失败的事件池
        this.rejectedEvent = [];
        //成功
        let resolve = (data) => {
            if(this.status === 'pending'){
                this.status = 'fulfilled';
                this.fulfilledEvent.forEach(fn=>fn())
            }
        }

        //失败
        let reject = (data) => {
            if(this.status === 'pending'){
                this.status = 'rejected';
                this.fulfilledEvent.forEach(fn=>fn())
            }
        }

        try{
            excutor(resolve,reject);

        }catch(e){
            reject(e)
        }
        
    }
    //是订阅：是往成功的事件池或失败的事件池中放入方法
    then(resolveFn,rejectedFn){
        if(this.status === 'pending'){
            this.fulfilledEvent.push(resolveFn);
            this.rejectedEvent.push(rejectedFn);
        }
    }
}

new Promise((resolve,reject) => {

})